#pragma once
#include "mnemonic.hpp"

typedef int Opcode;

Mnemonic get_mnemonic(Opcode op);

enum ChangeType { CHANGE_OP, CHANGE_ARGA, CHANGE_ARGB, CHANGE_RET };

ChangeType get_changetype(Opcode op);

Opcode to_opcode(Mnemonic, ChangeType);

// impl
#include "common.hpp"

inline Opcode to_opcode(Mnemonic mnem, ChangeType ct)
{
	// ct takes up the 3 least signficant bits. mnem the rest.
	const int mnem_value(static_cast<int>(mnem));
	return (mnem_value << 3) | ct;
}


inline Mnemonic get_mnemonic(Opcode op)
{
	const int mnemonic_part(op >> 3);
	const int normalized(mod(mnemonic_part, NUMBER_OF_MNEMONICS));
	return static_cast<Mnemonic>(normalized);
}

inline ChangeType get_changetype(Opcode op)
{
	const int change_part(op & 0x7); // last 3 bits
	const int normalized(change_part % 4); // four change types
	return static_cast<ChangeType>(normalized);
}




